
function tag_user(result)
{
    var obj = document.getElementById(result.id);
    var txtObj = document.getElementById(result.txtid);
    var before_html = '';
    var before_txt_html = '';
    if (txtObj) {
        before_txt_html = txtObj.innerHTML;
        if ('login' == result.type) {
            txtObj.innerHTML = 'Loading…';
        }
    } else if (obj) {
        before_html = obj.innerHTML;
        if ('login' == result.type) {
            obj.innerHTML = 'Loading…';
        }
    }
    if (obj) {
        obj.style.display="none";
    } else {
        obj = txtObj;
    }
    //步骤一:创建异步对象
    var ajax = new XMLHttpRequest();
    //步骤二:设置请求的url参数,参数一是请求的类型,参数二是请求的url,可以带参数,动态的传递参数starName到服务端
    ajax.open("post", "/api.php/Ajax/check_user.html?type="+result.type+"&img="+result.img+"&currentstyle="+result.currentstyle, true);
    //给头部添加ajax信息
    ajax.setRequestHeader("X-Requested-With","XMLHttpRequest");
    //步骤三:发送请求+数据
    ajax.send();
    //步骤四:注册事件 onreadystatechange 状态改变就会调用
    ajax.onreadystatechange = function () {
    //步骤五 如果能够进到这个判断 说明 数据 完美的回来了,并且请求的页面是存在的
        if (ajax.readyState==4 && ajax.status==200) {
            var json = ajax.responseText;  
            var res = JSON.parse(json);

            var winWidth = document.body.clientWidth;


            if (res.status) {
                if (1 == res.data.pcfcms_is_login) {
                    if (obj) {
                        if ('logout' == result.type) {
                            if (txtObj) {
                                txtObj.innerHTML = before_txt_html;
                            } else {
                                obj.innerHTML = before_html;
                            }

                            if(winWidth <= 1200){
                                obj.style.display="block";
                            }else{
                                obj.style.display="inline-block";
                            }

                        } else if ('reg' == result.type) {
                            obj.style.display="none";
                        }
                    }
                } else {
                    if (obj) {
                        if (txtObj) {
                            txtObj.innerHTML = before_txt_html;
                        } else {
                            obj.innerHTML = before_html;
                        }
                        if ('logout' == result.type) {
                            obj.style.display="none";
                        } else {
                            if(winWidth <= 1200){
                                obj.style.display="block";
                            }else{
                                obj.style.display="inline-block";
                            }
                        }
                    }
                }
            } else {
                if (obj) {
                    obj.innerHTML = 'Error';
                    if(winWidth <= 1200){
                        obj.style.display="block";
                    }else{
                        obj.style.display="inline-block";
                    }
                }
            }
      　}
    } 
}

// 读取 cookie
function getCookie(c_name)
{
    if (document.cookie.length>0)
    {
      c_start = document.cookie.indexOf(c_name + "=")
      if (c_start!=-1)
      { 
        c_start=c_start + c_name.length+1 
        c_end=document.cookie.indexOf(";",c_start)
        if (c_end==-1) c_end=document.cookie.length
            return unescape(document.cookie.substring(c_start,c_end))
      } 
    }
    return "";
}